<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
	$(function(){
		$("a[href='#maximize']").trigger("click");	
		$("#txtUserIdNewUser,#txtRealNameNewUser,#selSexNewUser,#txtBirthDayUserName,#ddlLiveProvinceNewUser,#ddlLiveCityNewUser,#ddlOriProvinceNewUser,#ddlOriCityNewUser,#txtQQNewUser").attr("disabled","disabled");
		loadCity("ddlLiveProvinceNewUser","ddlLiveCityNewUser");
		loadCity("ddlOriProvinceNewUser","ddlOriCityNewUser");
		$("#ddlLiveProvinceNewUser").bind("change",function(){loadCity("ddlLiveProvinceNewUser","ddlLiveCityNewUser");})
		$("#ddlOriProvinceNewUser").bind("change",function(){loadCity("ddlOriProvinceNewUser","ddlOriCityNewUser");})
		loadUserNewUser();		
		$("#btnSubmitNewUser").bind("click",submit);
	});	
	function submit(){
        var iconId = '';
        var icon = $("input[name='icon[]']").each(function(){
            if($(this).attr("checked")){
                iconId += ','+$(this).val();
            }
        });
		var params = {
					id:$("#hduid").val(),
					realname:$("#txtRealNameNewUser").val(),
					sex:$("#selSexNewUser").val(),
					birthday:$("#txtBirthDayNewUser").val(),
					provinceid:$("#ddlLiveProvinceNewUser").val(),
					cityid:$("#ddlLiveCityNewUser").val(),
					jgprovinceid:$("#ddlOriProvinceNewUser").val(),
					jgcityid:$("#ddlOriCityNewUser").val(),
					phone:$("#txtPhoneNewUser").val(),
					email:$("#txtEmailNewUser").val(),
					weibo:$("#txtWeiboNewUser").val(),
					qq:$("#txtQQNewUser").val(),
					isvalid:$("input[type='radio']:checked").val(),
					pwd:$("#txtPwdNewUser").val(),
                    iconId:iconId
				};


		$.ajax({
			type:"post",
			url:"admin.php/manage/modifyUser",
			dataType:"json",
			data:params,
			success:function(data){
				parent.loadUser();
				alert("修改成功");
				$("#btnCloseNewUser").trigger("click");
			}
		});
	}
	
	function loadUserNewUser(){
		var id = $("#hduid").val();
		var params = {id:id};
		$.ajax({
			type:"post",
			url:"admin.php/manage/getUserInfoById",
			dataType:"json",
			data:params,
			success:function(data){				
				$("#txtUserIdNewUser").val(data.user.id);
				$("#txtRealNameNewUser").val(data.user.realname);
				$("#selSexNewUser").val(data.user.sex);
				$("#txtBirthDayNewUser").val(data.user.birthday);
				$("#ddlLiveProvinceNewUser").val(data.user.provinceid);
				loadCity("ddlLiveProvinceNewUser","ddlLiveCityNewUser");
				$("#ddlLiveCityNewUser").val(data.user.cityid);
				$("#ddlOriProvinceNewUser").val(data.user.jgprovinceid);
				loadCity("ddlOriProvinceNewUser","ddlOriCityNewUser");
				$("#ddlOriCityNewUser").val(data.user.jgcityid);
				$("#txtPhoneNewUser").val(data.user.phone);
				$("#txtEmailNewUser").val(data.user.email);
				$("#txtWeiboNewUser").val(data.user.weibo);
				$("#txtQQNewUser").val(data.user.qq);
				$("input[type='radio'][value='"+data.user.isvalid+"']").trigger("click");
				$("#txtPwdNewUser").val(data.user.pwd);
                $("input[name='icon[]']").each(function(){

                    for(var i=0;i<data.icon.length;i++){
                        if($(this).val()==data.icon[i].icon_id){
                            $(this).attr('checked',true);
                        }
                    }
                });

			}
		});
	}
	
	function loadCity(p,c){
		$("#"+c).html("<option value=''>请选择...</option>");
		var pid = $("#"+p).val();
		if(IsEmpty(pid))
			return;
		var params = {provinceid : pid};
		$.ajax({
			type:"post",
			url:"admin.php/City/getByProvinceId",
			dataType:"html",
			data:params,
			async:false,
			success:function(data){
				$("#"+c).append(data);
			}
		});
	}
	function basicCard(){
		var id = $("#hduid").val();
		$("#hrefEditUserManage").attr("href","admin.php/manage/newuser?id="+id).text("基本信息");
		$("#hrefEditUserManage").trigger("click");
	}
	function albumCard(){
		var id = $("#hduid").val();
		$("#hrefEditUserManage").attr("href","admin.php/manage/album?id="+id).text("相册管理");
		$("#hrefEditUserManage").trigger("click");
	}
	function rzCard(){
		var id = $("#hduid").val();
		$("#hrefEditUserManage").attr("href","admin.php/manage/auditCard?id="+id).text("认证管理");
		$("#hrefEditUserManage").trigger("click");
	}
</script>
<div class="pageContent">
	<form class="pageForm required-validate"
		onsubmit="return validateCallback(this, navTabAjaxDone);">
		<div class="panelBar">
			<ul class="toolBar">

				<li style="display: none"><a id="hrefEditUserManage" class="edit"
					href="" lookupgroup="orgLookup"><span>修改</span></a></li>
				<li><a id="hrefDel" onclick="basicCard()" class="delete" href="javascript:void(0)"><span>基本信息</span></a></li>
				<li><a id="hrefExport" onclick="albumCard()" class="edit" href="javascript:void(0)"><span>相册管理</span></a></li>
				<li><a id="hrefExport" onclick="rzCard()" class="edit" href="javascript:void(0)"><span>认证管理</span></a></li>
			</ul>
		</div>
		<div class="pageFormContent" style="float: left; width: 500px;"
			layoutH="56">
			<table class="tableNewUser">
				<tr>
					<td>用户ID：</td>
					<td><input id="txtUserIdNewUser" type="text" value="" /></td>
				</tr>
				<tr>
					<td>姓名：</td>
					<td><input type="text" id="txtRealNameNewUser" /></td>
				</tr>
				<tr>
					<td>性别：</td>
					<td><select id="selSexNewUser" style="width: 120px">
							<option value="男">男</option>
							<option value="女">女</option>
					</select></td>
				</tr>
				<tr>
					<td>出生年月：</td>
					<td><input type="text" id="txtBirthDayNewUser" value=""></td>
				</tr>
				<tr>
					<td>所在城市：</td>
					<td><select id="ddlLiveProvinceNewUser"
						style="width: 120px; height: 25px;">
							<option value="">请选择...</option>
						<?php
						foreach ( $province as $key => $value ) {
							print "<option value='$key'>$value</option>";
						}
						?> 
						</select><select id="ddlLiveCityNewUser"
						style="width: 120px; height: 25px;">
							<option value="">请选择...</option>
					</select></td>


				</tr>
				<tr>
					<td>籍贯城市：</td>
					<td><select id="ddlOriProvinceNewUser" style="width: 120px; height: 25px;">
							<option value="">请选择...</option>
						<?php
						foreach ( $province as $key => $value ) {
							print "<option value='$key'>$value</option>";
						}
						?>
						</select> <select id="ddlOriCityNewUser"
						style="width: 120px; height: 25px;">
							<option value="">请选择...</option>
					</select></td>
				</tr>
				<tr>
					<td>手机号码：</td>
					<td><input type="text" id="txtPhoneNewUser"></td>
				</tr>
				<tr>
					<td>电子邮箱:</td>
					<td><input type="text" id="txtEmailNewUser"></td>
				</tr>
				<tr>
					<td>微薄账号:</td>
					<td><input type="text" id="txtWeiboNewUser"></td>
				</tr>
				<tr>
					<td>QQ:</td>
					<td><input type="text" id="txtQQNewUser"></td>
				</tr>
				<tr>
					<td>用户状态:</td>
					<td><input type="radio" name="userStatusNewUser" value="1"
						style="width: 20px" />有效 <input type="radio" name="userStatusNewUser"
						value="0" style="width: 20px" />无效</td>
				</tr>
				<tr>
					<td>用户密码:</td>
					<td><input type="text" id="txtPwdNewUser"></td>
				</tr>
                <tr>
                    <td>图标管理:</td>
                    <td>
                            <?php
                            $n=1;
                            foreach ( $icon as $key => $value ) {
                                print "<input type='checkbox' style='width:25px;' value='".$n."' name='icon[]'>".$value['name'];
                                $n++;
                            }
                            ?>
                    </td>
                </tr>
				<tr>
					<td colspan="2"></td>
				</tr>
			</table>
			<input type="hidden" id="hduid"
				value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

			<div class="buttonActive" style="width: 120px; margin-left: 80px;">
				<div class="buttonContent">
					<button id="btnSubmitNewUser" type="button" style="width: 80px">提 交</button>
				</div>
			</div>

			<div class="button">
				<div class="buttonContent">
					<button id="btnCloseNewUser" type="button" class="close"
						style="width: 80px">取 消</button>
				</div>
			</div>
		</div>

		<div class="pageFormContent"
			style="float: right; width: 460px; overflow: auto;" layoutH="56"
			id="divExistsNew"></div>
	</form>
</div>
